﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ras2ClassLib
{
    public class PerformerController
    {
        public IEnumerable<Performer> GetAllPerformers()
        {
            Ras2DBDataContext db = new Ras2DBDataContext();

            var result = from performer in db.Performers
                         orderby performer.Name ascending
                         select performer;

            return result;
        }

        public void UpdatePerformer(Performer s)
        {
            Ras2DBDataContext context = new Ras2DBDataContext();
            Performer original = (from a in context.Performers
                             where a.ID == s.ID
                             select a).SingleOrDefault();
            if (original != null)
            {
                original.Name = s.Name;
                original.Description = s.Description;
                original.Image = s.Image;
                original.Url = s.Url;
                context.SubmitChanges();
            }
        }

        public void AddPerformer(Performer s)
        {
            Ras2DBDataContext context = new Ras2DBDataContext();
            context.Performers.InsertOnSubmit(s);
            context.SubmitChanges();
        }

        public void DeletePerformer(Performer s)
        {
            Ras2DBDataContext context = new Ras2DBDataContext();
            context.Performers.Attach(s);
            context.Performers.DeleteOnSubmit(s);
            context.SubmitChanges();
        }		
    }
}
